//
//  DiscoveryViewController.m
//  ZHIFUBAO
//
//  Created by 高新川 on 15/6/16.
//  Copyright (c) 2015年 高新川. All rights reserved.
//

#import "DiscoveryViewController.h"
#import "DiscoverModel.h"
#import "UIColor+Hex.h"
//#import "UIButton+UIButtonImageWithTitle.h"

@interface DiscoveryViewController ()

@end

@implementation DiscoveryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"探索";
    [self initTableHead];
    self.tableView.tableHeaderView = _headView;
    
    UIView *food = [[UIView alloc] init];
    food.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = food;
    self.modal = [[DiscoverModel alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 初始化表头的视图
- (void)initTableHead {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
    UIButton *hongbao = [UIButton buttonWithType:UIButtonTypeCustom];
    hongbao.frame = CGRectMake(15, 20, 50, 70);
    [hongbao setImage:[UIImage imageNamed:@"adw_icon_apcoupon_normal"] forState:UIControlStateNormal];
    [hongbao setTitle:@"红包" forState:UIControlStateNormal];
    hongbao.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [hongbao setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    hongbao.titleLabel.tintColor = [UIColor blackColor];
    [hongbao setImageEdgeInsets:UIEdgeInsetsMake(-15, 5, 0, 0)];
    [hongbao setTitleEdgeInsets:UIEdgeInsetsMake(50, -40, 0, 0)];
    [hongbao addTarget:self action:@selector(clickedHongBao) forControlEvents:UIControlEventTouchDown];
    [headView addSubview:hongbao];
    
    UIButton *electronic = [[UIButton alloc] initWithFrame:CGRectMake(95, 20, 50, 70)];
    [electronic setImage:[UIImage imageNamed:@"adw_icon_coupon_normal"] forState:UIControlStateNormal];
    [electronic setTitle:@"电子卷" forState:UIControlStateNormal];
    electronic.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [electronic setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    electronic.titleLabel.tintColor = [UIColor blackColor];
    [electronic setImageEdgeInsets:UIEdgeInsetsMake(-15, 5, 0, 0)];
    [electronic setTitleEdgeInsets:UIEdgeInsetsMake(50, -40, 0, 0)];
    [electronic addTarget:self action:@selector(clickedElect) forControlEvents:UIControlEventTouchDown];
    [headView addSubview:electronic];
    
    UIButton *travel = [[UIButton alloc] initWithFrame:CGRectMake(175, 20, 50, 70)];
    [travel setImage:[UIImage imageNamed:@"adw_icon_travel_normal"] forState:UIControlStateNormal];
    [travel setTitle:@"旅游单" forState:UIControlStateNormal];
    travel.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [travel setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    travel.titleLabel.tintColor = [UIColor blackColor];
    [travel setImageEdgeInsets:UIEdgeInsetsMake(-15, 5, 0, 0)];
    [travel setTitleEdgeInsets:UIEdgeInsetsMake(50, -40, 0, 0)];
    [travel addTarget:self action:@selector(cleckedTravel) forControlEvents:UIControlEventTouchDown];
    [headView addSubview:travel];
    
    UIButton *vip = [[UIButton alloc] initWithFrame:CGRectMake(255, 20, 50, 70)];
    [vip setImage:[UIImage imageNamed:@"adw_icon_membercard_normal"] forState:UIControlStateNormal];
    [vip setTitle:@"会员卡" forState:UIControlStateNormal];
    vip.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [vip setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    vip.titleLabel.tintColor = [UIColor blackColor];
    [vip setImageEdgeInsets:UIEdgeInsetsMake(-15, 5, 0, 0)];
    [vip setTitleEdgeInsets:UIEdgeInsetsMake(50, -40, 0, 0)];
    [vip addTarget:self action:@selector(cleckedVIP) forControlEvents:UIControlEventTouchDown];
    [headView addSubview:vip];
    self.headView = headView;
}

// 几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 3;
    }
    else {
        return 1;
    }
}

// 几个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"   ";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellWithIdentifier = @"DiscoverCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellWithIdentifier];
    }
    DiscoverUnitl *unitl = [self.modal.datas objectAtIndex:(indexPath.section*3+indexPath.row)];
    cell.imageView.image = [UIImage imageNamed:unitl.image];
    cell.textLabel.text = unitl.title;
    cell.detailTextLabel.text = unitl.detail;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)clickedHongBao {
    NSLog(@"红包");
}

- (void)clickedElect {
    NSLog(@"电子卷");
}

- (void)cleckedTravel {
    NSLog(@"行程单");
}

- (void)cleckedVIP {
    NSLog(@"会员卡");
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
